<template>
  <div class="top">
    <div style="display: flex">
      <div class="left">
        <img src="../assets/img/re.png" class="re" />
        <!-- <img class="logo" src="../assets/img/logo.png" />
        <span>系统控制软件</span>
        <img class="bt" src="../assets/img/bt.png" /> -->
      </div>
      <div class="middle">
        <!-- <div v-for="(item, index) in list" @click="goPath(item, index)" :key="item" :class="{'active': index == active}">
                {{item}}
            </div> -->
      </div>
    </div>
    <div class="right">
      <img src="../assets/img/user.png" />
      <span>{{ name }}</span>
      <i class="el-icon-switch-button" @click="exit" />
    </div>
  </div>
</template>

<script>
export default {
  name: "HeaderTop",

  data() {
    return {
      list: ["场景管理", "资源管理", "报表管理", "数据管理", "系统管理"],
      active: 0,
      name: "",
    };
  },
  watch: {
    $route(route) {
      console.log(9);
      if (route) {
        if (this.$route.path.indexOf("scene") > -1) {
          this.title = "场景管理";
          this.active = 0;
        } else if (this.$route.path.indexOf("assets") > -1) {
          this.title = "资源管理";
          this.active = 1;
        } else if (this.$route.path.indexOf("report") > -1) {
          this.title = "报表管理";
          this.active = 2;
        } else if (this.$route.path.indexOf("data") > -1) {
          this.title = "数据管理";
          this.active = 3;
        } else if (this.$route.path.indexOf("system") > -1) {
          this.title = "系统管理";
          this.active = 4;
        }
        this.$store.commit("settings/SET_INDEX", this.active);
        console.log(this.$route.path, this.active);
      }
    },
  },
  mounted() {
    this.active = this.$store.state.settings.headIndex;
    console.log(this.$store.state.user.name);

    this.name = sessionStorage.getItem("name");
    if (this.name !== "admin") {
      this.list.splice(this.list.length - 1, 1);
    }
  },

  methods: {
    exit() {
      this.$alert("确认退出？", "提示", {
        confirmButtonText: "确定",
        callback: (action) => {
          console.log(9);
          this.$router.push({ path: "/login" });
          // this.$message({
          //   type: 'info',
          //   message: `action: ${ action }`
          // });
          // this.$router.push({path: '/login'})
        },
      });
    },
    goPath(item, index) {
      this.active = index;
      if (index == 0) {
        this.$router.push("/scene/mag");
      } else if (index == 1) {
        this.$router.push("/assets/device");
      } else if (index == 2) {
        this.$router.push("/report/report");
      } else if (index == 3) {
        this.$router.push("/data/record");
      } else if (index == 4) {
        this.$router.push("/system/user");
      }
      this.$store.commit("settings/SET_INDEX", index);
    },
  },
};
</script>

<style lang="scss" scoped>
.top {
  height: 64px;
  background: url("../assets/img/header.png");
  background-size: 100% 100%;
  width: 100%;
  display: flex;
  justify-content: space-between;
}
.right {
  color: white;
  line-height: 64px;
  margin-right: 30px;
  i {
    cursor: pointer;
  }
  span {
    display: inline-block;
    margin: 0 15px;
  }
  img {
    width: 20px;
    vertical-align: middle;
  }
}
.left {
  align-self: center;
  width: 235px;
  position: relative;
  .logo {
    width: 48px;
    height: 48px;
    margin-left: 20px;
  }
  span {
    font-weight: 700;
    font-style: oblique;
    font-size: 26px;
    color: #ffffff;
    display: inline-block;
    margin-left: 10px;
    position: absolute;
    top: 10px;
  }
  .bt {
    position: absolute;
    bottom: 3px;
    left: 81px;
  }
}
.middle {
  display: flex;
  margin-top: 15px;
  margin-left: 50px;
  div {
    background: url("../assets/img/rect-black.png");
    background-size: 100% 100%;
    width: 111px;
    color: white;
    height: 32px;
    line-height: 32px;
    text-align: center;
    font-style: oblique;
    margin-right: 20px;
    cursor: pointer;
  }
  .active {
    background: url("../assets/img/rect.png");
    background-size: 100% 100%;
    font-weight: bold;
  }
}
.re {
  width: 250px;
  height: 67px;
}
</style>
